--#include "data\config\cross\CrossBossAttackConfig.lua" once


--[[
刷新BOSS来袭
]]
function CrossAttackBossStart()
	local dVar = System.getDyanmicVar()
	dVar.crossAttackBossKillNum = 0
	dVar.crossAttackBossMobBoss = {}
	System.broadcastTipmsg(Lang.ScriptTips.CrossBossAttack001, ttChatWindow+ttScreenCenter)
end

--[[
刷新BOSS来袭
]]
function CrossAttackBossFreshBatchMonsters( batchIdx )
	batchIdx = tonumber(batchIdx)
	local openDay = 1	--System.getDaysSinceOpenServer() 		--跨服服务器，强制为1
	--print("AttackBossFreshMonsters, batchIdx="..batchIdx..", openDay="..openDay)
	local freshCfg = CrossAttackBossGetFreshCfgByOpenDay( openDay )
	if not freshCfg then
		return
	end

	local monsters = freshCfg.freshMonsters[batchIdx]
	if not monsters then
		return
	end

	for i, oneMonster in ipairs( monsters ) do
		freshSceneMonsterInRangeForce( oneMonster, 0 )			--强制刷出
	end

	System.broadcastTipmsg( string.format(Lang.ScriptTips.CrossBossAttack002, batchIdx), ttChatWindow+ttScreenCenter)
end


function CrossAttackBossGetFreshCfgByOpenDay( openDay )
	for i, freshCfg in ipairs( CrossBossAttackConfig ) do
		if freshCfg.openServerDay[1] <= openDay and openDay <= freshCfg.openServerDay[2] then
			return freshCfg
		end
	end
	return nil
end

function CrossAttackBossOnMonsterDie(monster, sysarg, monId, lastHitKiller)
	local dVar = System.getDyanmicVar()
	if not dVar.crossAttackBossKillNum then
		dVar.crossAttackBossKillNum = 0
	end
	dVar.crossAttackBossKillNum = dVar.crossAttackBossKillNum + 1
	--print("AttackBossOnMonsterDie, ")
	CrossAttackBossFressBoss( dVar.crossAttackBossKillNum )
end

function CrossAttackBossFressBoss( killNum )
	--print("CrossAttackBossFressBoss, killNum="..killNum)
	local bossCfg = CrossAttackBossGetBossByKillNum( killNum )
	if not bossCfg then
		return
	end

	local dVar = System.getDyanmicVar()
	if not dVar.crossAttackBossMobBoss then
		dVar.crossAttackBossMobBoss = {}
	end
	local freshNum = dVar.crossAttackBossMobBoss[bossCfg.bossIdx] or 0
	--print("AttackBossFressBoss, bossIdx="..bossCfg.bossIdx..", freshNum="..freshNum)
	if freshNum > 0 then
		return
	end
	dVar.crossAttackBossMobBoss[bossCfg.bossIdx] = 1			--已刷出BOSS
	--print("CrossAttackBossFressBoss, --> bossIdx="..bossCfg.bossIdx)
	for i, oneBoss in ipairs( bossCfg.boss ) do
		--print("CrossAttackBossFressBoss, --> bossIdx="..oneBoss.monsterId)
		freshSceneMonsterInRangeForce( oneBoss, 0 )
	end
	System.broadcastTipmsg( string.format(Lang.ScriptTips.CrossBossAttack003, killNum), ttChatWindow+ttScreenCenter)
end


function CrossAttackBossGetBossByKillNum( killNum )
	local openDay  = 1		--System.getDaysSinceOpenServer()		--跨服服务器，强制为1
	local freshCfg = CrossAttackBossGetFreshCfgByOpenDay( openDay )
	if not freshCfg then
		return nil
	end
	for bossIdx, bossCfg in ipairs( freshCfg.freshBoss ) do
		if killNum >= bossCfg.killMonsterNum then
			return bossCfg
		end
	end
	return nil
end